import { Module } from '@nestjs/common'
import { JwtModule } from '@nestjs/jwt'
import { ConfigModule, ConfigService } from '@nestjs/config'
import { AuthService } from './auth.service'

@Module({
  imports: [
    JwtModule.registerAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      global: true,
      useFactory: (configService: ConfigService) => ({
        secret: configService.get<string>(
          'JWT_SECRET',
          process.env.JWT_SECRET || 'secretKey'
        ),
        signOptions: { expiresIn: '24h' } // 默认过期时间为24小时
      })
    })
  ],
  providers: [AuthService],
  exports: [AuthService]
})
export class AuthModule {}
